<template>
	<view>
		<form @submit="formSubmit">
			<view class="uni-form-item item_horizon">
				<view class="title">标题</view>
				<input type="text" placeholder="请输入名称..." v-model="addForm.raider.title">
			</view>
			<view class="uni-form-item ">
				<view class="title">简介</view>
				<textarea  placeholder="请输入简介..." auto-height class="simple_text" v-model="addForm.raider.reason"/>
			</view>		
			<view class="uni-form-item ">
				<view class="title">正文</view>
				<textarea id="editor" class="ql-container"  v-model="addForm.raider.content"  :maxlength="1000"/>
			</view>	
			<view class="uni-form-item ">
				<view class="title">图片</view>
				<view class="img-field">
					<image class="img-add" v-for="item in imagepaths" v-if="imagepaths" :src='item'></image>
					<view class="img-add" @click="addImage">
					<text>+</text>
					</view>
				</view>
			</view>
			<view class="space">
				
			</view>
			<button form-type="submit" >提交</button>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addForm:{
					article:{
						pictures:[{
							filePath:""
						},
						{
							filePath:""
						},
						{
							filePath:""
						},
						{
							filePath:""
						},
						{
							filePath:""
						}
						]
					},
					raider:{
						title:"",
						reason:"",
						content:""
					},
					userID:10001
				},
				imagepaths:[]
				
				
			}
		},
		methods: {
			sliderChange(){
				
			},
			formSubmit(){
				var that=this
				uni.showModal({
				    title: '提示',
				    content: '是否确认发布？',
				    success: function (res) {
				        if (res.confirm) {
				           that.Submit()
						   uni.switchTab({
						   	url:'/pages/index/index'
						   })
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			},
			async Submit(){
				console.log(this.addForm)
				const res=await this.$myDoPost({
					url:'/RaiderArticle/api/addRaiderArticle',
					data:this.addForm
				})
			},
			 /*onEditorReady() {		                		                
			   uni.createSelectorQuery().select('#editor').context((res) => {
			   this.editorCtx = res.context
			    }).exec()           
			 },
			chooseLocation(){
				var that=this;
				uni.chooseLocation({
					latitude: 30.526230995480322,
					longitude: 114.35812750362396,
				    success: function (res) {
				        console.log('位置名称：' + res.name);
				        that.address=res.address
				        console.log('纬度：' + res.latitude);
				        console.log('经度：' + res.longitude);
				    }
				});
			},*/
			addImage() {
				var that=this;
			    uni.chooseImage({
			        count: 3, 
			        sourceType: ['album'], //从相册选择
			        success: (res) => {			
			           res.tempFilePaths.forEach(item=>
					   {
						   that.imagepaths.push(item)
					   })
						
			        }
			    });
			}
		}
	}
</script>

<style lang="less">	
	button{
		background-color:#F0AD4E;
		color: #FFFFFF;
		margin-top: -30px;
	}
	page{
		padding-top:50rpx;
	}
	.item_horizon{
			display: flex;
	}
	.item_img{
		margin-top: 100rpx;
	}
	.space{
		width:100%;
		height: 70px;
	}
.uni-form-item{
	padding-left: 40rpx;
	padding-right: 40rpx;
	justify-content: space-between;
	align-items: center;
	margin-bottom:30rpx ;
	input{
	height: 80rpx;
	padding-left: 20rpx;
	padding-right: 20rpx;
	background: #fff;
	width:80%;
	border: 1px solid #f8f8f8;
	border-radius: 10rpx;
	}
	.simple_text{
		background: #fff;
		width:100%;
		min-height: 200rpx;
		border: 1px solid #f8f8f8;
		border-radius: 10rpx;
		float: right;
		margin-top: 20rpx;
		margin-bottom: 15rpx;
		
	}
	#editor{
		width: 100%;
		height: 600px;
		background-color: #fff;
	}

	.img-field{
		display: flex;
		margin-top:20rpx;
		.img-add{
			width:180rpx;
			height:200rpx;
			text-align: center;
			background-color:#C0C0C0;
			margin-right: 10rpx;
			text{
				font-size: 50px;
				line-height: 100px;
			}
		}
	}
}

</style>
